package com.hzx.ssm.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class JedisPoolUtil {
    public JedisPoolUtil() {
        // TODO 自动生成的构造函数存根
    }
    private static volatile JedisPool jedisPool;
    public static JedisPool getJedisPoolInstance() {
        if(null == jedisPool) {
            synchronized (JedisPoolUtil.class) {
                if(null == jedisPool) {
                    JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
                    jedisPoolConfig.setMaxTotal(200);
                    jedisPoolConfig.setMaxIdle(32);
                    jedisPoolConfig.setMaxWaitMillis(100*1000);
                    jedisPoolConfig.setBlockWhenExhausted(true);
                    jedisPoolConfig.setTestOnBorrow(true);

                    jedisPool = new JedisPool(jedisPoolConfig,"127.0.0.1",6379,60000);
                }
            }

        }
        return jedisPool;
    }

    public static void release(JedisPool jedisPool) {
        if(null != jedisPool)
            jedisPool.close();
    }
}
